# coding=utf-8
import logging
from django.views.generic import ListView, DetailView
from mezzanine.generic.models import Keyword
from article.models import Category, Article

logger = logging.getLogger('article')


class ArticleDetailView(DetailView):
    model = Article
    template_name = 'pages/article_detail.html'
    pk_url_kwarg = 'article_id'

    def get_context_data(self, **kwargs):
        context = super(ArticleDetailView, self).get_context_data(**kwargs)
        #context['category_list'] = Category.objects.all()
        category = self.object.category
        context['page'] = category.page_ptr
        return context


class TagView(ListView):
    paginate_by = 10
    template_name = 'pages/article_list_of_tag.html'

    def get_queryset(self):
        tag = self.kwargs.get('tag')
        return Article.objects.filter(keywords__keyword__title=tag)

    def get_context_data(self, **kwargs):
        context = super(TagView, self).get_context_data(**kwargs)
        context['tag'] = Keyword.objects.get(title=self.kwargs.get('tag'))
        return context